package user

import (
	"APi/response"
	"common/pkg"
	"github.com/gin-gonic/gin"
	"time"
)

func Upload(c *gin.Context) {
	file, err := c.FormFile("file")
	if err != nil {
		response.CurrencyErrResponse(c, -1, err.Error())
		return
	}
	dst := "D:\\GoWork\\src\\takeout\\common\\file\\" + file.Filename
	if err = c.SaveUploadedFile(file, dst); err != nil {
		response.CurrencyErrResponse(c, -1, err.Error())
		return
	}
	filename := time.Now().String() + file.Filename
	err = pkg.Upload(dst, filename)
	if err != nil {
		response.CurrencyErrResponse(c, -1, err.Error())
		return
	}
	fileUrl := "https://jjlbuckets.oss-cn-shanghai.aliyuncs.com/" + filename
	response.CurrencySuccessResponse(c, "文件上传成功", map[string]interface{}{"FileUrl:": fileUrl})
}
